< previous page page_487 next page >

Page 487
'Fill up combo box list from INI file and select the user's
'last chosen item
nCount = Cint(sGetINI(sINIFile, "Regions", "Count", 0) )
For i = 1 to nCount
cmbRegn.AddItem sGetINI(sINIFile, "Regions", "Region" & i,"?")
Next i

cmbRegn.Text = sGetINI(sINIFile, "Regions", _
               "LastRegion",cmbRegions.List(0))

End Sub
The code in Listing 21.4 first checks the INI file for a username. By providing the default value ?, you know whether the username already exists in the INI file and can prompt for it. The default value is a great feature because it does not matter whether the INI file even exists.
The next part of the code sample reads the number of regions from the INI file and uses that value to place each region in a combo box. The final statement sets the Text property of the combo box to a value from the INI file, using the first item in the list as a default.
note.gif Remember that writeINI is a subroutine, so it does not require parentheses. square.gif

Driving your program from INI files, as demonstrated in Listing 21.4, allows you to make minor changes to the program quickly and easily without even recompiling it.
From Here . . .
In this chapter, you looked at some of the file functions built in to the VB language, as well as examined how to use INI files in your application. From Visual Basic, you can copy, delete, and rename files, as well as store information in a variety of formats. Although the methods discussed in this chapter do not have the power of a database engine, they are well suited to simple tasks in which you cannot have a lot of extra overhead.
For more information about the topics discussed in this chapter, see the following chapters:
If you want to learn about more advanced methods of information storage, see Chapter 24, "Database Basics."
To find out additional information about API functions, see Chapter 20, "Accessing the Windows API."
To learn more about text file access from a Web browser, see Chapter 30, "Using VBScript."

 
< previous page page_487 next page >